package com.jili.dynamic;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/**
 * ClassName: LogAdvice
 * Package com.jili.dynamic
 * Description:
 *
 * @Author: 廖继礼
 * @Create: 2025/3/9
 * @Version: v1.0
 */
@Component
@Aspect
@Slf4j
public class LogAdvice {

    @Before("com.jili.dynamic.MyPointCut.pointCut()")
    public void before(JoinPoint joinPoint) {
        // 获取方法属于类的信息
        String simpleName = joinPoint.getClass().getSimpleName();
        log.info("simpleName is {}", simpleName);
        // 获取方法名称
        String name = joinPoint.getSignature().getName();
        log.info("name is {}", name);
        // 获取参数列表
        Object[] args = joinPoint.getArgs();
        log.info("args is {}", args);
        log.info("方法开始之前");
    }

    @After("com.jili.dynamic.MyPointCut.pointCut()")
    public void after() {
        log.info("方法结束了");
    }

    @AfterThrowing("com.jili.dynamic.MyPointCut.pointCut()")
    public void error() {
        log.info("方法报错了");
    }

    @AfterReturning(value = "com.jili.dynamic.MyPointCut.pointCut()", returning = "result")
    public void returnResult(JoinPoint joinPoint, Object result) {
        log.info("result is {}", result);
        log.info("方法返回了");
    }
}
